package mapdemo;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

class Students implements Comparable<Students> {

    private String sid; //学号
    private String name; //姓名
    private int score; //分数

    public Students() {
    }

    public Students(String sid, String name, int score) {
        this.sid = sid;
        this.name = name;
        this.score = score;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public int compareTo(Students s) {
        return s.getScore()-this.getScore();
    }

    @Override
    public String toString() {
        return "Students{" +
                "sid='" + sid + '\'' +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}

public class MapSortDemo {

    public static void main(String[] args) {
        Map map = new TreeMap();

        map.put(new Students("S001", "张三", 89), "北京市");
        map.put(new Students("S002", "李四", 98), "北京市");
        map.put(new Students("S003", "王五", 78), "北京市");
        map.put(new Students("S004", "赵六", 90), "北京市");

        Set<Map.Entry> entries = map.entrySet();
        for (Map.Entry entry : entries) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }
}
